package net.toocruel.iqismart.web.controller.home.profile;

import net.toocruel.iqismart.entity.rbac.User;
import net.toocruel.iqismart.service.UserService;
import net.toocruel.iqismart.service.core.*;
import net.toocruel.iqismart.service.dto.ProfileEmailDTO;
import net.toocruel.iqismart.utils.FileUploadUtils;
import net.toocruel.iqismart.web.controller.base.AbstractBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/5/14 下午2:12
 */
@Controller
@RequestMapping("profile")
public class ProfileOauthController extends AbstractBaseController {
    @Autowired
    private QuestionService questionService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private UserService userService;

    @Autowired
    private TagService tagService;

    @Autowired
    private ArticleService articleService;

    @Autowired
    private GoodService goodService;

    @Autowired
    private FileUploadUtils fileUploadUtils;



    @GetMapping("oauth")
    public ModelAndView email(){
        ModelAndView modelAndView = new ModelAndView(getTemplate("oauth"));
        return modelAndView;
    }


    @PostMapping("oauth")
    public ModelAndView email(ProfileEmailDTO dto, HttpServletRequest request, HttpServletResponse response, HttpSession session){
        //
        ModelAndView modelAndView = new ModelAndView(getTemplate("oauth"));
        try {

            refreshCurrentUser();
        }catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("error",e);
        }

        modelAndView.addObject("dto",dto);
        return modelAndView;
    }



    @Override
    protected String getModule() {
        return "profile";
    }

    @ModelAttribute
    public User user(){
        return userService.getById(getCurrentUser().getId());
    }



}
